﻿using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using Happy.Examples.OrderManagement.Domain.Orders;

namespace Happy.Examples.OrderManagement.Domain.Test.Orders
{
    [TestClass]
    public class OrderTest
    {
        [TestMethod]
        public void Order_Total_Test()
        {
            var order = TestHelper.CreateOrderInNewState();

            Assert.AreEqual(0, order.Total);


            order.AddOrderItem(new OrderItem(Guid.NewGuid(), "苹果", price: 10, quantity: 4));
            order.AddOrderItem(new OrderItem(Guid.NewGuid(), "香蕉", price: 3, quantity: 10));
            order.AddOrderItem(new OrderItem(Guid.NewGuid(), "橘子", price: 5, quantity: 2));

            Assert.AreEqual(80, order.Total);


            order.RemoveOrderItem(order.OrderItems.First().ProductId);

            Assert.AreEqual(40, order.Total);


            order.UpdateOrderItem(order.OrderItems.Last().ProductId, quantity: 4);

            Assert.AreEqual(50, order.Total);
        }
    }
}
